###############################################################################
# SuperLinks                                                                  #
# Copyright (c) 2000-2007 Greg Nolle (http://greg.nolle.co.uk)                #
###############################################################################
# This program is free software; you can redistribute it and/or modify it     #
# under the terms of the GNU General Public License as published by the Free  #
# Software Foundation; either version 2 of the License, or (at your option)   #
# any later version.                                                          #
#                                                                             #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       #
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   #
# more details.                                                               ##                                                                             #
# You should have received a copy of the GNU General Public License along     #
# with this program; if not, write to the Free Software Foundation, Inc.,     #
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                 #
###############################################################################
# Libraries/Logs.pm.pl -> Logs library                                        #
###############################################################################
# DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING!                         #
###############################################################################
package Logs;

BEGIN { require "System.pm.pl";  import System  qw($SYSTEM ); }
BEGIN { require "General.pm.pl"; import General qw($GENERAL); }

use strict;

sub new {
  my $class = shift;
  my $self  = {
    "HANDLE"  => undef,
    "PRINTER" => undef,
    "PRINT"   => 0,
    @_
  };
  return bless ($self, $class);
}

sub DESTROY {}

###############################################################################
# Header subroutine
sub Header {
  my $self = shift;

  my $Return = <<HTML;
<html>

<head>
<title>Log</title>
<link type="text/css" href="$SYSTEM->{'PUBLIC_URL'}/cpstyles.css" rel="stylesheet">
</head>

<body>
<font class="body">
HTML

  print $Return if ($self->{'PRINT'});
  
  return $Return;
}

###############################################################################
# Footer subroutine
sub Footer {
  my $self = shift;

  my $Return = <<HTML;
</font>
</body>

</html>
HTML

  print $Return if ($self->{'PRINT'});
  
  return $Return;
}

###############################################################################
# Line subroutine
sub Line {
  my $self = shift;
  my ($Message, $Command) = @_;

  if ($self->{'PRINTER'}) {
    $Message = &{ $self->{'PRINTER'} }($self, $Message, $Command);
  } else {
    if ($Command eq "uplevel") {
      $Message = "<ul>";
    } elsif ($Command eq "downlevel") {
      $Message = "</ul>";
    } elsif ($Command eq "element") {
      $Message = "<li>$Message";
    } elsif ($Command eq "error") {
      $Message = "<font color=\"Red\">$Message</font>";
    } elsif ($Command eq "success") {
      $Message = "<font color=\"Green\">$Message</font>";
    } elsif ($Command eq "check") {
      $Message = "<font color=\"Olive\">$Message</font>";
    }

    $Message =~ s/\n/\<br\>/g;
  }

  $self->{'LOG'} .= $Message;

  if ($self->{'HANDLE'}) {
    print { $self->{'HANDLE'} } $Message;
  }

  print $Message if ($self->{'PRINT'});

  return $Message;
}

1;